package com.opener.common.code.assistant.model;

import java.util.List;

public class Tab {
    private String table;
    private List<Prop> props;
    private String tableNamePrefix = "t_hr_";

    public String getTableNamePrefix() {
        return tableNamePrefix;
    }

    public void setTableNamePrefix(String tableNamePrefix) {
        this.tableNamePrefix = tableNamePrefix;
    }

    public String getTable() {
        return table;
    }
    public String getClassName(){
        String[] a = table.replaceFirst("^"+ tableNamePrefix,"").split("_");
        StringBuffer cls = new StringBuffer();
        for (int i = 0; i< a.length; i++){
            String segment = a[i];
            if ("".equalsIgnoreCase(segment) ){
                continue;
            }
            segment = segment.replaceAll("^\\w",segment.substring(0,1).toUpperCase());
            cls.append(segment);
        }
        return cls.toString();
    }

    public void setTable(String table) {
        this.table = table;
    }

    public List<Prop> getProps() {
        return props;
    }

    public void setProps(List<Prop> props) {
//        Collections.sort(props, new Comparator<Prop>() {
//            @Override
//            public int compare(Prop o1, Prop o2) {
//                int ret = o1.getDbField().compareToIgnoreCase(o2.getDbField());
//                return ret;
//            }
//        });
        this.props = props;
    }
}
